package com.leonardo.beanme.fields;

import java.util.Date;
import java.util.Hashtable;

import com.leonardo.beanme.fields.impl.BooleanInput;
import com.leonardo.beanme.fields.impl.ComboInput;
import com.leonardo.beanme.fields.impl.DateInput;
import com.leonardo.beanme.fields.impl.DefaultInput;
import com.leonardo.beanme.fields.impl.DoubleInput;
import com.leonardo.beanme.fields.impl.FloatInput;
import com.leonardo.beanme.fields.impl.IntegerField;
import com.leonardo.beanme.fields.impl.LongInput;
import com.leonardo.beanme.fields.impl.RadioInput;
import com.leonardo.beanme.model.ComboBox;
import com.leonardo.beanme.model.RadioBox;

public class TypeToField {
	
	private static final int N_CLASSES = 9;
	private static Hashtable classToField = new Hashtable(N_CLASSES);
	
	public static boolean acceptType(Class clazz) {
		return classToField.containsKey(clazz);
	}
	
	public static Class getField(Class clazz) {
		return acceptType(clazz) ? (Class)classToField.get(clazz) : DefaultInput.class;  
	}
	
	//Costumized configuration
	public static void setTypeField(Class type, Class field) {
		classToField.put(type, field);
	}
	
	static {
		classToField.put(Integer.class, IntegerField.class);
		classToField.put(Long.class, LongInput.class);
		classToField.put(Double.class, DoubleInput.class);
		classToField.put(Float.class, FloatInput.class);
		classToField.put(String.class, DefaultInput.class);
		classToField.put(Boolean.class, BooleanInput.class);
		classToField.put(Date.class, DateInput.class);
		classToField.put(ComboBox.class, ComboInput.class);
		classToField.put(RadioBox.class, RadioInput.class);
	}
	
}
